package com.example.cs342messenger;

import java.util.List;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.LinearLayout;
import android.widget.SimpleAdapter;
import android.widget.TextView;

public class ConversationListViewAdapter extends ArrayAdapter{

	private LinearLayout wrapper;
	private List<String> people;
	private TextView textView;
	
	public ConversationListViewAdapter (Context context, int textViewResourceId, List<String> peeps){
		super(context, textViewResourceId, peeps);
		people = peeps;
	}
	
	
	public int getCount(){
		return people.size();
	}
	
	public String getItem(int index){
		return people.get(index);
	}
	
	public View getView(int position, View convertView, ViewGroup parent) {
		View row = convertView;
		if (row == null) {
			LayoutInflater inflater = (LayoutInflater) this.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			row = inflater.inflate(R.layout.convo_effect, parent, false);
		}
		
		System.out.println("The New Messages:");
		for(int i = 0; i < ConversationList.newMessage.size(); i++){
			System.out.println(ConversationList.newMessage.get(i));
		}
		
		TextView tv1 = (TextView)row.findViewById(R.id.theText);
		if(ConversationList.newMessage.contains(people.get(position))){
			tv1.setBackgroundColor(0xFF00FF00);
		}else{
			tv1.setBackgroundColor(0x00000000);
		}
		tv1.setText(people.get(position));
		return row;
	}
	
	public Bitmap decodeToBitmap(byte[] decodedByte) {
		return BitmapFactory.decodeByteArray(decodedByte, 0, decodedByte.length);
	}
	
}
